const axios = require("axios")

const fs = require("fs")

async function getPage(num) {

    let pageUrl = 'http://www.app-echo.com/api/recommend/sound-day?page=' + num
    let res = await axios.get(pageUrl)
    // console.log(res.data);

    res.data.list.forEach((value, index) => {
        let title = value.sound.name
        let mp3Url = value.sound.source
        console.log(title);
        console.log(mp3Url);
        download(mp3Url, title)
    });
}

async function download(mp3Url, title) {

    let res = await axios.get(mp3Url, {
        responseType: "stream"
    })

    let ws = fs.createWriteStream("./MP3/" + title + ".mp3")

    res.data.pipe(ws)

    res.data.on("close", function () {
        ws.close()
    })
}
getPage(1)